package Servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

import redis.clients.jedis.Jedis;

import DAL.Entites.OrderItem;
import DAL.JDBC.DBConn;
import DAL.JDBC.JedisConn;
import DAL.JDBC.OrderItemJDBC;
import DAL.JDBC.OrderJDBC;
import DAL.JDBC.UserJDBC;

public class SaveCart extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public SaveCart() {
        super();
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		JSONObject result = new JSONObject();
		OrderItemJDBC orderItemJDBC = new OrderItemJDBC(DBConn.getConnection());
		OrderJDBC orderJDBC = new OrderJDBC(DBConn.getConnection());
		UserJDBC userJDBC = new UserJDBC(DBConn.getConnection());
		
		Jedis jedis = JedisConn.getConnection();
		/*String uid = request.getSession().getAttribute("uid").toString();
		String email = request.getSession().getAttribute("email").toString();
		int creditCard = Integer.parseInt(request.getParameter("creditCard"));
		String Feedback = request.getParameter("feedBack");
		int userId = userJDBC.getUserByEmail(email).getId();
		
		int orderId = orderJDBC.insert(new Date(), userId, creditCard, Feedback);
		
		List<String> items = new ArrayList<String>();
		for (Object item : jedis.smembers("carts:"+uid)) {
			items.add(item.toString());
			orderItemJDBC.insert(orderId, Integer.parseInt(item.toString()));
		}
		*/
		try {
			//result.put("order", items);
			result.put("result", true);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		PrintWriter pw = response.getWriter();
		pw.write(result.toString());
		
	}

}
